/**
 * IndexAction.java
 * Created at 2018-1-3
 * Created by zhanghailin
 * Copyright (C) 2018 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.app.index.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.broadtext.app.index.service.IndexService;
import com.broadtext.common.annotation.AppControllerAspect;
import com.broadtext.common.exp.DaoException;
import com.broadtext.common.utils.StringUtils;
import com.broadtext.rms.system.service.ILoginService;
import com.broadtext.rms.system.service.ISysUserService;

/**
 * <p>ClassName: IndexAction</p>
 * <p>Description: TODO</p>
 * <p>Author: zhanghailin</p>
 * <p>Date: 2018-1-3</p>
 */
@Controller
@RequestMapping("/app/index")
public class IndexAction {
    
    /**
     * 注入service
     */
    @Autowired
    @Qualifier("indexService")
    private IndexService indexService;
    
    /**
     * 登录服务
     */
    @Autowired
    @Qualifier("loginService")
    private ILoginService loginService;
    
    /**
     * 用户Service
     */
    @Autowired
    @Qualifier("sysUserService")
    private ISysUserService sysUserService;
    
    
    /**
     * 
     * <p>Description: app首页电池地图分布接口</p>
     * @return
     */
    @RequestMapping(value = "/getIndexMapData.mvc")
    @ResponseBody
    public Map<String, Object> getIndexMapData(HttpServletRequest request, HttpServletResponse response){
        /*Map<String, Object> map = this.indexService.getIndexMapData();
        return map;*/
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> params = new HashMap<String, Object>();
        //获取请求用户名
        String loginName = request.getParameter("loginName");
        if(StringUtils.isNotBlank(loginName)) {
            try {
                Map<String, Object> checkMap = this.sysUserService.getUserClass(loginName);
                if(null != checkMap && "true".equals(checkMap.get("flag").toString())){
                    //该用户是客户账号
                    params.put("cusId", checkMap.get("cusId"));
                }
                map = this.indexService.getIndexMapData(params);
            } catch (DaoException e) {
                e.printStackTrace();
            }
            
        }
        return map;
    }
    
    /**
     * 
     * <p>Description: app首页电池地图分布接口</p>
     * @return
     */
    @AppControllerAspect
    @RequestMapping(value = "/getIndexBasicData.mvc")
    @ResponseBody
    public Map<String, Object> getIndexBasicData(HttpServletRequest request, HttpServletResponse response){
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> params = new HashMap<String, Object>();
        //获取请求用户名
        String loginName = request.getParameter("loginName");
        if(StringUtils.isNotBlank(loginName)) {
            try {
                Map<String, Object> checkMap = this.sysUserService.getUserClass(loginName);
                if(null != checkMap && "true".equals(checkMap.get("flag").toString())){
                    //该用户是客户账号
                    params.put("cusId", checkMap.get("cusId"));
                }
                map = this.indexService.getIndexBasicData(params);
            } catch (DaoException e) {
                e.printStackTrace();
            }
            
        }
        return map;
        
    }
    
    

}
